package com.glasses.business.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.glasses.business.R;
import com.glasses.business.base.MyBaseAdapter;
import com.glasses.business.entity.HomeProduct;
import com.glasses.business.entity.User;
import com.glasses.business.utils.SimpleDraweeViewUtil;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/6
 * Version：1.0
 */

public class HomeAdapter extends MyBaseAdapter<HomeProduct, HomeAdapter.ViewHolder> {


    public HomeAdapter(Activity context, List data) {
        super(context, data);
    }

    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_home, null));
    }

    @Override
    protected void onBindViewHolder_(ViewHolder holder, int position) {
        if (data != null && data.size() > 0) {
            HomeProduct homeProduct = data.get(position);
            Uri parse = Uri.parse(homeProduct.getPicture());
            SimpleDraweeViewUtil.showThumb(context,parse,holder.homeImgView);
//            holder.homeImgView.setImageURI(homeProduct.getPicture());
            String name = homeProduct.getName();
            String text = "[专业推荐套餐]"+name;
            SpannableString spanString = new SpannableString(text);
            ForegroundColorSpan span = new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent));
            spanString.setSpan(span, 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            holder.professionSet.setText(spanString);
        }

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.homeImgView)
        SimpleDraweeView homeImgView;
        @InjectView(R.id.professionSet)
        TextView professionSet;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
